import { map, reduce, split, compose, trim, assoc, adjust, fromPairs, toPairs, join, filter, all } from 'ramda';

export const camelCase: (input: string) => string = input =>
    input.replace(/-([a-z])/g, (_, c) => c.toUpperCase())

export const kebabCase: (i: string) => string = input => 
    input.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`)

function smi(i32: number) {
  return i32 >>> 1 & 0x40000000 | i32 & 0xbfffffff;
}

export const hashString: (string: string)=> string = string => {
  // This is the hash from JVM
  // The hash code for a string is computed as
  // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
  // where s[i] is the ith character of the string and n is the length of
  // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
  // (exclusive) by dropping high bits.
  let hash = 0;
  for (let ii = 0; ii < string.length; ii++) {
    hash = 31 * hash + string.charCodeAt(ii) | 0;
  }
  return (2147483647 + smi(hash)).toString(32);
}